/*
 * @Author: AskMeWhy
 * @Date: 2020-12-27 11:58:47
 * @Last Modified by: AskMeWhy
 * @Last Modified time: 2020-12-31 18:06:42
 */
const app = getApp();
const { AskComponent } = app._require("common/index");
const date = new Date();
const year = Number(date.getFullYear() - 10);
date.setFullYear(year + 10+50);
const defaultMax = date.getTime();
date.setFullYear(year - 200);
const defaultMin = date.getTime();
AskComponent({
    properties: {
        inline: {
            type: Boolean,
            value: false,
        },
        isShowBeginDate:{
            type: Boolean,
            value: false,
        },
        isDateFormatter:{
            type:Boolean,
            vale:false
        },
        type: {
            type: String,
            value: "datetime",
        },
        title: {
            type: String,
            value: "",
        },
        placeholder: {
            type: String,
            value: "",
        },
        list: {
            type: Array,
            value: [],
        },
        value: {
            type: String,
            optionalTypes: [Number],
            value: "",
            observer: "formatValue",
        },
        minDate: {
            type: Number,
            value: defaultMin,
        },
        maxDate: {
            type: Number,
            value: defaultMax,
        },
        currentDate:{
            type: Number,
            value: defaultMax,
        }
    },
    data: {
        show: false,
        valueText: "",
        beginDate: new Date(1970,0,1).getTime(),

        formatter(type, value) {
            if (type === "year") {
                return `${value}年`;
            } else if (type === "month") {
                return `${value}月`;
            }else if (type === "day") {
                return `${value}日`;
            }else if (type === "hour") {
                return `${value}时`;
            }else if (type === "minute") {
                return `${value}分`;
            }

            return value;
        },
        dateformatter(type, value) {
            if (type === "year") {
                return `${value}年`;
            } else if (type === "month") {
                return `${value}月`;
            }else if (type === "day") {
                return `${value}日`;
            }
            return value;
        },
    },
    methods: {
        formatValue() {
            let valueText = "";
            console.log(this.data.vale);


            if (this.data.value || this.data.value === 0) {
                if(this.data.isDateFormatter){
                    valueText = new Date(this.data.value).format("yyyy-MM-dd");
                }else{
                    valueText = new Date(this.data.value).format("yyyy-MM-dd hh:mm");
                }

            }

            // console.log(valueText);

            this.setData({
                valueText: valueText,

            });
        },
        onInput(e) {
            this.$emit("input", { value: e.detail });
        },
        showPopup() {
            this.setData({
                show: true,
            });
        },
        onClose() {
            this.setData({ show: false });
        },
        onConfirm(e) {
            // console.log(e);
            // return
            // console.log(this.data.isDateFormatter);
            this.$emit("sure", { value: e.detail });
            this.setData({ show: false });
        },
        onCancel() {
            this.setData({ show: false });
        },
    },
});
